﻿using LoveEat.API.Read.Applications.Commands.Aquaculture;
using LoveEat.API.Read.Applications.Commands.Deep;
using LoveEat.API.Read.Applications.Commands.Goods;
using LoveEat.API.Read.Applications.Commands.Paths;
using LoveEat.API.Read.Applications.Commands.Slaughter;
using LoveEat.API.Read.DTOs;
using LoveEat.Domain;
using LoveEat.Domain.Aquaculture;
using LoveEat.Domain.Deep;
using LoveEat.Domain.Goods;
using LoveEat.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LoveEat.API.Read.Controllers
{
    /// <summary>
    /// API控制器—读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ManagementController> logger;
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public ManagementController(ILogger<ManagementController> logger,IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }
        /// <summary>
        /// 商品显示方法
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public  Task<APIResult<APIPaging<GoodsDTO>>> GoodsShow([FromQuery] GoodsQueryCommand command)
        {
            try
            {
                logger.LogInformation("商品显示成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("商品显示失败"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 商品名称下拉框显示方法
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<GoodsNameModel>>> GoodsNameShow()
        {
            try
            {
                GoodsNameQueryCommand command = new GoodsNameQueryCommand();
                logger.LogInformation("商品名称下拉框显示成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("商品名称下拉框显示失败"+ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 商品信息详情页反填方法
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<GoodsDTO>>> BackGoodsShow([FromQuery] GoodsBackQueryCommand command)
        {
            try
            {
                logger.LogInformation("商品信息反填成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("商品信息反填失败" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 图片显示方法
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<PathModel>>> PathShow()
        {
            try
            {
                PathQueryCommand command = new PathQueryCommand();
                logger.LogInformation("图片显示成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("图片显示失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 养殖信息反填
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<AquacultureDTO>>> AquacultureShow([FromQuery] AquacultureQueryCommand command)
        {
            try
            {
                logger.LogInformation("养殖信息反填成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("养殖信息反填失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 保健信息显示方法
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<HealthModel>>> HealtShow()
        {
            try
            {
                HealthQueryCommand command = new HealthQueryCommand();
                logger.LogInformation("保健信息显示成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("保健信息显示失败"+ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 屠宰信息显示方法
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<slaughterDTO>>> SlaughterShow()
        {
            try
            {
                slaughterQueryCommand command=new slaughterQueryCommand();
                logger.LogInformation("屠宰信息显示成功");
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("屠宰信息显示失败");
                
                throw;
            }
        }


        /// <summary>
        /// 深加工查询方法
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<DeepModel>>> DeepShow()
        {   
            DeepQueryCommand  command=new DeepQueryCommand();
            return mediator.Send(command);
       
        }


    }
}
